<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="缴费日期">
        <el-date-picker
          v-model="dateRange"
          end-placeholder="结束日期"
          range-separator="-"
          size="small"
          start-placeholder="开始日期"
          style="width: 240px"
          type="daterange"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="缴费渠道" prop="costWay">
        <el-select v-model="queryParams.costWay" placeholder="请选择缴费渠道" clearable>
          <el-option
            v-for="dict in dict.type.COST002"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
        <el-form-item label="收费员" prop="nickName">
          <el-select v-model="queryParams.nickName" placeholder="请输入收费员" clearable >
            <el-option v-for="(item, index) in createrOptions" :key="index" :label="item.nickName"
                       :value="item.nickName" :disabled="item.disabled" ></el-option>
          </el-select>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" size="small" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >收费日报表</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="feeDailyReportList">
      <el-table-column label="收费员" align="center" prop="nickName" />
      <el-table-column  :formatter="numberFormat"  label="缴费笔数" align="center" prop="costSum" />
      <el-table-column  :formatter="numberFormat"  label="缴费金额" align="center" prop="costMoneySum" />
      <el-table-column  :formatter="numberFormat"  label="退款笔数" align="center" prop="refundSum" />
      <el-table-column  :formatter="numberFormat"  label="退款金额" align="center" prop="refundMoneySum" />
      <el-table-column  :formatter="numberFormat"  label="返还笔数" align="center" prop="returnSum" />
      <el-table-column  :formatter="numberFormat"  label="返还金额" align="center" prop="returnMoneySum" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listUser,getFeeDailyReport} from "@/api/report/feeDailyReport";
export default {
  name: "FeeDailyReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 日期范围
      dateRange: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 缴费信息表格数据
      feeDailyReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startDate: null,
        endDate: null,
      },
      createrOptions:[{}],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.createrSelect();
  },
  methods: {
    numberFormat (row, column, cellValue) {
      cellValue += ''
      if (!cellValue.includes('.')) cellValue += '.'
      return cellValue.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
        return $1 + ','
      }).replace(/\.$/, '')
    },
    createrSelect(){
      listUser().then(response => {
        this.createrOptions = response.rows;
      });
    },
    /** 查询缴费信息列表 */
    getList() {
      this.loading = true;
      getFeeDailyReport(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.feeDailyReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        nickName: null,
        costSum: null,
        costMoneySum: null,
        refundSum: null,
        refundMoneySum: null,
        reyurnSum: null,
        returnMoneySum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createrSelect();
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/report/feeDailyReport/export', {
        ...this.queryParams
      }, `收费日报表_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style>

</style>

